
package com.activitycode.tools;
import android.util.Log;
import android.util.Xml;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlSerializer;

public class PullXmlUtil
{
  public static String getListForXml(List<Map<String, Object>> paramList, String paramString)
  {
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    XmlSerializer localXmlSerializer = Xml.newSerializer();
    String str1 = "";
    try
    {
      localXmlSerializer.setOutput(localByteArrayOutputStream, "UTF-8");
      localXmlSerializer.startDocument("UTF-8", Boolean.valueOf(true));
      Iterator localIterator1 = paramList.iterator();
      while(localIterator1.hasNext()) {
          Map localMap;
          Iterator localIterator2;
          str1 = "";
    	  localMap = (Map)localIterator1.next();
          localXmlSerializer.startTag(null, paramString);
          localIterator2 = localMap.keySet().iterator();
          while (localIterator2.hasNext()) {
              String str2 = (String)localIterator2.next();
              String str3 = (String)localMap.get(str2);
              localXmlSerializer.startTag(null, str2);
              localXmlSerializer.text(str3);
              localXmlSerializer.endTag(null, str2);
          }
          localXmlSerializer.endTag(null, paramString);
      }
      localXmlSerializer.endDocument();
      localByteArrayOutputStream.flush();
      localByteArrayOutputStream.close();
      str1 = localByteArrayOutputStream.toString().replace("<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>", "");

    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {

    }
    catch (IllegalStateException localIllegalStateException)
    {
      str1 = "";
    }
    catch (IOException localIOException)
    {
      str1 = "";
    }
    return str1;
  }

  public static List<Map<String, Object>> getXmlForList(String xml, String tag)
  {
	  ArrayList localArrayList = null;
    try
    {
      String str1 = tag + "";
      HashMap localHashMap;
      XmlPullParser localXmlPullParser;
      
      int i;
      if ((!xml.equals("<" + str1 + "><" + tag + "/></" + str1 + ">")) && (!xml.equals("<" + tag + "/>"))) {
    	  //:cond_2
          String str2 = replaceStr(xml);
          localArrayList = null;
          localHashMap = null;
          localXmlPullParser = XmlPullParserFactory.newInstance().newPullParser();
          localXmlPullParser.setInput(new ByteArrayInputStream(str2.getBytes()), "UTF-8");
          i = localXmlPullParser.getEventType();
          //:goto_1
          while (i != 1) {
        	  String str3 = localXmlPullParser.getName();
        	  switch (i)
              {
              case 1:
              default:
                i = localXmlPullParser.next();
                break;
              case 0:
                localArrayList = new ArrayList();
                i = localXmlPullParser.next();
                break;
              case 2:
                if (tag.equals(str3)) {
                  localHashMap = new HashMap();
  
                }
                else {
                	//:cond_4
                	if (localHashMap != null) {
                        try
                        {
                          localHashMap.put(str3, localXmlPullParser.nextText());
                        }
                        catch (Exception localException2)
                        {
                          localHashMap.put(str3, "");
                        }             		
                	}
                }
                //:cond_3
                //:goto_2
                int k = localXmlPullParser.next();
                i = k;
                //:goto_1
                break;
              case 3:
                if (tag.equals(str3))
                {
                  localArrayList.add(localHashMap);
                  localHashMap = null;
                }
               	//:cond_5

                int j = localXmlPullParser.next();
                i = j;
                break;
              }
          }
      }
      else {
    	  //:cond_0
    	  localArrayList = null;
      }
      //:cond_1
      return localArrayList;
      


    }
    catch (Exception localException1)
    {

        
    }
    //:cond_1
    //:goto_0
    return localArrayList;
  }

  public static List<Map<String, Object>> getXmlForList(String xml, String tag, String[] imgFiled, String imgUrl)
  {
    ArrayList tagList = null;
    HashMap map;
    XmlPullParser parser;
    String nodeName;
    int flg;
    String text;
    int n;
    int event;
    try
    {
      String str1 = tag + "";
      if ((!xml.equals("<" + str1 + "><" + tag + "/></" + str1 + ">")) && (!xml.equals("<" + tag + "/>"))&&(!xml.equals("<" + str1 + "><" + tag + "></" + tag + "></" + str1 + ">"))) {
    	  //:cond_2
    	  String str2 = replaceStr(xml);
          tagList = null;
          map = null;
          parser = XmlPullParserFactory.newInstance().newPullParser();
          parser.setInput(new ByteArrayInputStream(str2.getBytes()), "UTF-8");
          event = parser.getEventType();
          //:goto_1
          while (event != 1){
        	  nodeName = parser.getName();
        	  //Log.d("nodeName####### ",  "i is " + event + " str3 " + nodeName);
        	  switch (event)
              {

              case XmlPullParser.END_DOCUMENT:
              default:
                event = parser.next();
                break;
              case XmlPullParser.START_DOCUMENT:
                tagList = new ArrayList();
                event = parser.next();
                break;
              case XmlPullParser.START_TAG:
                if (tag.equals(nodeName)) {
                  map = new HashMap();
                }
                else{
                	//:cond_4
                	if (map != null){
                        flg = 0;
                        try
                        {
                          text = parser.nextText();
                          if (imgFiled != null) {
                        	  n = 0;  //v5
                              //:goto_3
                              while (n < imgFiled.length) {
                            	  //:cond_6
                            	  if ((imgFiled[n].equals(nodeName)) && (text != null))
                                  {
                                    flg = 1;
                                    //mod by guoq-s
                                    //map.put(nodeName, imgUrl + text.replace(".", "_si."));
                                    map.put(nodeName, imgUrl + text);
                                    //mod by guoq-e
                                    break;
                                  }
                            	  else {
                            		  //:cond_7
                            		  n++;
                            	  }
                              }
                          }
                       	  //:cond_5
                          //:goto_4
                          if (flg == 0) {
                        	  map.put(nodeName, text);
                          }

                          
                        }
                        catch (Exception localException2)
                        {
                        	map.put(nodeName, "");
                        }	
                	}
                }
                //:cond_3
                //:goto_2
                event = parser.next();

                break;

              case XmlPullParser.END_TAG:
                  if (tag.equals(nodeName))
                  {
                    tagList.add(map);
                    //Log.i("taglist##3#######", "" + tagList);
                    map = null;
                  }
                  int j = parser.next();
                  event = j;
                  break;
              }
          }
      }
      else {
    	  //:cond_0
    	  tagList = null;
      }

      Log.d("***********PullXmlUtil", "size is " + tagList.size());
    }
    catch (Exception localException1)
    {
  
    }
    //:cond_1
    //:goto_0
    
    return tagList;
    
  }

  private static String replaceStr(String paramString)
  {
	  String str;
    if ("".equals(paramString)){
    	str = "-";
    }
    else {
    	str = paramString.replace("&", "&amp;").replace("'", "&apos;").replace("\"", "&quot;");
    }
   return str;
  }
}

/* Location:           D:\06_microbo\03_tools\jd-gui-0.3.3.windows\shanghai.jar
 * Qualified Name:     com.duostec.util.PullXmlUtil
 * JD-Core Version:    0.6.0
 */